Skip to content

Add comprehensive error handling to image lifecycle#61

Merged
chorrell merged 1 commit intomainfrom
add-error-handling
Feb 10, 2026
Merged

Add comprehensive error handling to image lifecycle#61
chorrell merged 1 commit intomainfrom
add-error-handling

Conversation

@chorrell
Copy link
Owner

Summary

Adds robust error handling to image build and cleanup operations to prevent resource leaks and provide better visibility into failures.

Changes

In create_image:

  • ✅ Catch Docker build failures with clear error messages
  • ✅ Re-raise exceptions appropriately to fail tests
  • ✅ Provides context when builds fail

In delete_image:

  • ✅ Guard against nil @image (if build never completed)
  • ✅ Wrap container cleanup in error handling
  • ✅ Continue cleanup even if individual containers fail
  • ✅ Handle NotFoundError if image already removed
  • ✅ Always attempt image removal even if container cleanup fails
  • ✅ Add informative status messages

Problem Solved

Before: If Docker image build failed, cleanup would crash trying to remove a nil image. If container cleanup failed, image removal would be skipped, leaving dangling images.

After: Cleanup is resilient and continues even when errors occur, preventing resource leaks.

Benefits

Graceful failures - Clear error messages when builds fail
Prevents resource leaks - Cleanup attempts even after failures
Better debugging - Status messages show what's happening
Resilient cleanup - Individual failures don't prevent overall cleanup

Testing

✅ All existing tests pass with new error handling
✅ Verified delete_image handles nil @image safely
✅ Cleanup messages appear in test output
✅ No behavioral changes for successful test runs

Improvements to create_image:
- Catch and report Docker build failures with clear error messages
- Re-raise exception to fail tests appropriately

Improvements to delete_image:
- Guard against nil @image (if build failed)
- Wrap container cleanup in error handling to continue if issues occur
- Catch individual container cleanup failures and continue
- Handle NotFoundError if image already removed
- Always attempt image removal even if container cleanup fails
- Add informative status messages for debugging

Benefits:
- Tests fail gracefully with clear error messages
- Cleanup attempts even after failures (prevents resource leaks)
- Better visibility into what's happening during cleanup
- Prevents cascading failures from cleanup issues

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@chorrell chorrell merged commit 03246a7 into main Feb 10, 2026
1 check passed
@chorrell chorrell deleted the add-error-handling branch February 10, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant